//
//  UIBarButtonItem + Extensions.swift
//  GHWeibo
//
//  Created by LGH on 2017/8/4.
//  Copyright © 2017年 LGH. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    /// 自定义barButtonItem
    ///
    /// - Parameters:
    ///   - titile: 标题
    ///   - normalColor: 颜色
    ///   - higlightedColor: 高亮时的颜色
    ///   - target: 添加监听的target
    ///   - action: 添加监听的方法
    convenience init(titile: String, normalColor: UIColor = UIColor.darkGray, higlightedColor: UIColor = UIColor.orange, target: Any?, action: Selector) {
        let btn = UIButton()
        btn.setTitle(titile, for: .normal)
        btn.setTitleColor(UIColor.darkGray, for: .normal)
        btn.setTitleColor(UIColor.orange, for: .highlighted)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        btn.addTarget(target, action: action, for: .touchUpInside)
        btn.sizeToFit()
        
        self.init(customView: btn)
    }
    
    convenience init(titile: String, normalColor: UIColor = UIColor.darkGray, higlightedColor: UIColor = UIColor.orange, imageName: String, highlightedImageName: String ,target: Any?, action: Selector) {
        let btn = UIButton()
        btn.setTitle(titile, for: .normal)
        btn.setTitleColor(UIColor.darkGray, for: .normal)
        btn.setTitleColor(UIColor.orange, for: .highlighted)
        btn.setImage(UIImage(named: imageName), for: .normal)
        btn.setImage(UIImage(named: highlightedImageName), for: .highlighted)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        btn.addTarget(target, action: action, for: .touchUpInside)
        btn.sizeToFit()
        
        self.init(customView: btn)
    }
}
